package com.uqbar.asteroids.components;

import java.awt.Color;
import java.awt.Font;

import com.uqbar.asteroids.scenes.AsteroidScene;
import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Label;

public class Marcador extends GameComponent<AsteroidScene> {

	private int value;
	private int lives;
	private int levelValue;
	
	

	public int getLevelValue() {
		return levelValue;
	}

	public void setLevelValue(int levelValue) {
		this.levelValue = levelValue;
	}

	public Marcador(double x, double y, Color color) {		
		super(new Label(new Font("verdana",  Font.BOLD, 16), color, "0"), x, y);
		this.value = 0;
		this.levelValue = 0;
		this.lives = 3;
	}

	public int getLives() {
		return lives;
	}

	public void setLives(int lives) {
		this.lives = lives;
	}
	
	public int getValue() {
		return value + levelValue;
	}

	public void setValue(int value) {
		this.value = value;
	}
	
	public void hit(int n) {

		this.setLevelValue(this.getLevelValue() + n);
		if(this.win(this.getScene())){
			this.getScene().fin();
		}
	}
	
	public void resetLevelValue(){
		this.setValue(this.getValue() + this.getLevelValue() - this.getScene().getMaxScore());
		this.setLevelValue(0);
	}
	
	public void decreaseLive(){
		this.setLives(this.getLives() -1);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		((Label)this.getAppearance()).setText("Vidas: " + Integer.toString(this.getLives()) + " Puntaje: " +Integer.toString(this.getValue()) + "/" + this.getScene().getMaxScore()); 
		super.update(deltaState);
	}


	public boolean win(AsteroidScene scene) {
		return this.getLevelValue() >= scene.getMaxScore();
	}
	
	public boolean gameOver(){
		return this.getLives() <= 0;
	}
	

}
